// mine/pages/recipesinfo/index.js
const $api = require("../../../api/mine").API

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl:"https://img01.yzcdn.cn/vant/apple-1.jpg",
    columns:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t = this
    t.setData({
      week:options.week
    })
    t.getWeekType()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var t =this
    t.getTeacherDietInfo()

  },
  // 获取星期
  getWeekType(){
    var t = this
    var columns = wx.getStorageSync('week')
    if(columns){
      t.setData({
        columns:columns
      })
      return false
    }
    $api.getWeekType().then(res=>{
      wx.setStorageSync('week', res.data)
      t.setData({
        columns:res.data
      })
    })
  },
  // 选择星期
  chooseweek(e){
    var t = this
    console.log(e)
    t.setData({
      week:e.currentTarget.dataset.dict_key
    })
    t.getTeacherDietInfo()
  },
  getTeacherDietInfo(){
    var t = this,
    data = {
      institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
      week:t.data.week,
      member_id:wx.getStorageSync('memberinfo').member_id
    }
    $api.getTeacherDietInfo(data).then(res=>{
      t.setData({
        lists:res.data
      })
    })
  },
  // 删除菜谱
  del_diet(e){
    var t= this,
    data = {
      institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
      member_id:wx.getStorageSync('memberinfo').member_id,
      child_diet_id:e.currentTarget.dataset.id
    }
    wx.showModal({

      title: '提示',
 
      content: '删除食谱',
 
      success: function (res) {
 
        if (res.confirm) {//这里是点击了确定以后
 
          $api.deleteTeacherDiet(data).then(res=>{
            console.log(res)
            wx.showToast({
              title: '删除成功',
            })
            t.onShow()
          })
 
        } else {//这里是点击了取消以后
 
          console.log('用户点击取消')
 
        }
 
      }
 
    })
  }
})